package com.liuyanzhao.ssm.blog.mapper.impl;

import com.liuyanzhao.ssm.blog.entity.UserArticle;
import com.liuyanzhao.ssm.blog.mapper.ArticleCategoryRefMapper;
import com.liuyanzhao.ssm.blog.mapper.UserArticleMapper;
import com.liuyanzhao.ssm.blog.service.UserArticleService;
import lombok.extern.slf4j.Slf4j;
import com.liuyanzhao.ssm.blog.entity.ArticleCategoryRef;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@Slf4j
public class UserArticleServiceImpl implements UserArticleService {
    @Autowired
    private ArticleCategoryRefMapper articleCategoryRefMapper;
    @Autowired
    private UserArticleMapper userArticleMapper;
    /**
     * 根据ID查询
     *
     * @param userId 用户ID
     * @return 用户收藏的文章ID列表
     */
    @Override
    public List<Integer> getArticleByUser(Integer userId) {
        System.out.println("success");
        return userArticleMapper.getArticleByUser(userId);
    }

    /**
     * 添加
     *
     * @param userArticle 插入的元素
     * @return 插入的个数
     */
    @Override
    public int insert(UserArticle userArticle) {
        articleCategoryRefMapper.insert(new ArticleCategoryRef(userArticle.articleId, 100000007));
        return userArticleMapper.insert(userArticle);
    }

    /**
     * 查询是否存在
     *
     * @param userArticle 查询的对象
     * @return 存在的个数
     */
    @Override
    public int query(UserArticle userArticle) {
        System.out.println("success");
        return userArticleMapper.query(userArticle);
    }

    /**
     * 删除
     *
     * @param userArticle 删除的对象
     * @return 删除的个数
     */
    @Override
    public int delete(UserArticle userArticle) {
        System.out.println("success");
        articleCategoryRefMapper.delete(new ArticleCategoryRef(userArticle.articleId, 100000007));
        return userArticleMapper.delete(userArticle);
    }
}
